﻿@page "/"
@using DataBindingTwo.Code

<h1>Form Validation</h1>
<p>Click Submit button to trigger validation</p>

<div class="row">
    <div class="col-md-6">
        <EditForm Model="_profile" OnValidSubmit="HandleValidSubmit">
            <DataAnnotationsValidator />
            <ValidationSummary />
            <div class="form-group">
                <label for="first_name">First Name</label>
                <InputText id="first_name" @bind-Value="_profile.FirstName" class="form-control"/>
            </div>
            <div class="form-group">
                <label for="last_name">Last Name</label>
                <InputText id="last_name" @bind-Value="_profile.LastName"  class="form-control"/> 
            </div>
            <div class="form-group">
                <label for="gender">Gender</label>
                <InputSelect id="gender" @bind-Value="_profile.Gender" class="form-control">
                    <option value="">Select Gender</option>
                    <option value="F">Female</option>
                    <option value="M">Male</option>
                </InputSelect>
            </div>
            <div class="form-group">
                <label for="dob">Date of Birth</label>
                <InputDate id="dob" @bind-Value="_profile.DateOfBirth" class="form-control"/>
            </div>
            <div class="form-group">
                <label for="age">Age</label>
                <InputNumber id="age" @bind-Value="_profile.Age" class="form-control"/>
            </div>
            <div class="form-check">
                <InputCheckbox id="married_status" @bind-Value="_profile.IsMarried" class="form-check-input" />
                <label for="married_status">Is Married?</label>
            </div>
            <div class="form-group">
                <label for="personal_bio">Personal Bio</label>
                <InputTextArea @bind-Value="_profile.PersonalBio" class="form-control"></InputTextArea>
            </div>
            <br/>
            <button type="submit">Submit</button>
        </EditForm>

        <br/>
        <br/>
        <table class="table"> 
            <tr>
                <td>Name</td>
                <td>@_profile.FirstName @_profile.LastName</td>
            </tr>
            <tr>
                <td>Gender</td>
                <td>@_profile.Gender</td>
            </tr>
            <tr>
                <td>Date of Birth</td>
                <td>@_profile.DateOfBirth</td>
            </tr>
            <tr>
                <td>Age</td>
                <td>@_profile.Age</td>
            </tr>
            <tr>
                <td>Is Married?</td>
                <td>@_profile.IsMarried</td>
            </tr>
            <tr>
                <td>Personal Bio</td>
                <td>@_profile.PersonalBio</td>
            </tr>
        </table>
    </div>
</div>

@code {
    private Profile _profile = new Profile();

    private void HandleValidSubmit()
    {
        Console.WriteLine("OnValidSubmit");
    }
}
